package controller;

import org.junit.Test;
import pojo.ChangeRoom;
import service.ChangeRoomService;
import service.ChangeRoomServiceImpl;
import service.ChangeRoomService;
import service.ChangeRoomServiceImpl;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;


public class ChangeRoomController {
    private ChangeRoomService service = new ChangeRoomServiceImpl();
    /*
        查询所有换房信息
     */
    @Test
    public void findAll() {
        ArrayList<ChangeRoom> list = service.findAll();
        for(ChangeRoom changeRoom : list) {
            System.out.println(changeRoom);
        }
    }

    /*
        条件查询，根据id查询换房信息
     */
    @Test
    public void findBychangeRoomId() {
        ChangeRoom changeRoom = service.findById(1);
        System.out.println(changeRoom);
    }

    /*
        添加换房信息  ***********************************************因为外键约束问题导致无法插入新数据
     */
    @Test
    public void insert() {
        ChangeRoom changeRoom = new ChangeRoom(1,100006,203,1,202,4,new Date(),6);
        int result = service.insert(changeRoom);

        if(result!=0) {
            System.out.println("添加成功");
        }else {
            System.out.println("添加失败");
        }
    }

    /*
        修改换房信息
     */
    @Test
    public void update() {
        ChangeRoom changeRoom = service.findById(1);
        try {
            changeRoom.setChange_time((new SimpleDateFormat("yyyy-MM-dd").parse("2022-03-02")));
        } catch (ParseException e) {
            e.printStackTrace();
        }

        int result = service.update(changeRoom);

        if(result != 0) {
            System.out.println("修改成功");
        }else {
            System.out.println("修改失败");
        }
    }

    /*
        删除换房信息
     */
    @Test
    public void delete() {
        int result = service.delete(service.findById(1));

        if(result != 0) {
            System.out.println("删除成功");
        }else {
            System.out.println("删除失败");
        }
    }
}
